package com.dimpt.cloud.userauth.model;

import com.dimpt.cloud.dataservice.aaa.model.Token;
import com.dimpt.cloud.dataservice.aaa.model.User;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 缓存的用户会话信息
 */
@Data
public class SessionSO {
    //会话id
    private String id;

    /**
     * 账户信息缓存，可以根据需求扩展
     */
    private String userName;
    private List<String> roles;
    private String level;
    private String provinceId;

    /**
     * 客户端地址和端口
     */
    private String clientAddress;
    private String clientPort;

    /**
     * 服务器地址加端口
     */
    private String serverAddress;
    private String serverPort;


    public SessionSO(User user, Token token){
        List<String> rolesList = new ArrayList<String>();
        rolesList.add(user.getDefaultRole());
        this.roles = rolesList;
        this.userName = user.getUserName();
        this.level = user.getLevel();
        this.provinceId = user.getProvinceId();

        this.clientAddress = token.getClientAddress();
        this.clientPort = token.getClientPort();
        this.serverAddress = token.getServerAddress();
        this.serverPort = token.getServerPort();
    }

}
